package com.bw.a2207a.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

/**
 *
 * @ClassName: BaseActivity
 * @Description: 通过传入ViewModel获取 具体实例
 * @Author: zhangyanchao
 * @CreateDate: 2024/10/16 4:05 PM
 * @Version: 1.0
 */
abstract class BaseActivity2<DB : ViewDataBinding, VM : ViewModel>(val layoutId: Int,val vm:VM) :
    AppCompatActivity() {

    //延时初始化 lateinit
    lateinit var binding: DB
    lateinit var viewModel: VM


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, layoutId)
        binding.lifecycleOwner = this

        //ViewModelProvider,获取viewModel 对象
        viewModel = ViewModelProvider(this)[vm::class.java]


        initView()
        initData()
    }

    abstract fun initData()

    abstract fun initView()


    override fun onDestroy() {
        super.onDestroy()
        binding.unbind()
    }
}